#ifndef CHECKHELPER_H
#define CHECKHELPER_H

#include "..\Parser\Common\ParseContext.h"
#include "..\Node\Common\ExecuteContext.h"

namespace CExpression
{
class AssertHelper
{
public:
	static bool CreateHandlerExists(const ExpressionString &op,ParseContext &context,const ExpressionString &errorMsg)
	{
		std::map<ExpressionString,ParseContext::CreateNodeHandlerPtr>::iterator iter=ParseContext::createHandlerMap->find(op);
		if(iter==ParseContext::createHandlerMap->end())
		{
			context.SetError();
			context.SetErrorMsg(errorMsg);
			return false;
		}
		else
		{
			return true;
		}
	}

	static bool AreSameType(ExecuteRunTimeType type1,ExecuteRunTimeType type2,ExecuteContext &context,const ExpressionString &msg)
	{
		if(context.ErrorOccured())
		{
			return false;
		}
		if(type1!=type2)
		{
			context.SetError();
			context.SetErrorMsg(msg);
			return false;
		}
		return true;
	}

	static bool ExpectType(ExecuteRunTimeType source,ExecuteRunTimeType expected,ExecuteContext &context,const ExpressionString &msg)
	{
		if(context.ErrorOccured())
		{
			return false;
		}
		if(source!=expected)
		{
			context.SetError();
			context.SetErrorMsg(msg);
			return false;
		}
		return true;
	}
};
}

#endif